package com.example.controller;

import ch.qos.logback.classic.Logger;
import com.example.entity.DailyInspection;
import com.example.ext.entity.ExtDailyInspection;
import com.example.mapp.DailyInspectionMapp;
import com.example.service.DailyInspectionService;
import com.example.util.ResultUtil;
import io.swagger.annotations.ApiOperation;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by simon on 2017/10/20.
 */
@RestController
public class DailyInspectionController {

    private final static Logger logger = (Logger) LoggerFactory.getLogger(DailyInspectionController.class);

    @Autowired
    DailyInspectionService dailyInspectionService;

    @Autowired
    DailyInspectionMapp dailyInspectionMapp;

    @ApiOperation(value = "查询列表的信息",notes = "查询列表的信息")
    @RequestMapping(value="api/inspection/getInspectionList",method = RequestMethod.POST)
    Map<String,Object> getInspectionList(@RequestBody ExtDailyInspection extDailyInspection){

        return dailyInspectionService.queryListByElevatorId(extDailyInspection);
    }

    @ApiOperation(value = "新增巡检信息",notes = "新增巡检信息")
    @RequestMapping(value="api/inspection/add",method = RequestMethod.POST)
    Map<String,Object> add(@RequestBody DailyInspection dailyInspection){

        return dailyInspectionService.add(dailyInspection);
    }

    @ApiOperation(value = "查询巡检信息",notes = "查询巡检信息")
    @RequestMapping(value="api/inspection/{id}",method = RequestMethod.POST)
    Map<String, Object> queryById(@PathVariable String id){
        try{
            ExtDailyInspection dailyInspection = dailyInspectionMapp.queryById(id);
            return ResultUtil.returnSuccess("成功", dailyInspection);

        }catch( Exception e ){
            logger.error("查询失败", e);
            return ResultUtil.returnError("查询失败", null);
        }

    }
}
